package app.map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.amap.api.services.help.Tip;

import java.util.List;

import menhoo.com.i8officelibrary.R;

/**
 * Created by ThinkPad on 2017/5/5.
 */

public class AddresAdapter extends BaseAdapter {

    private List<Tip> datas;
    private Context context;
    public AddresAdapter(Context context, List<Tip> datas){
        this.context = context;
        if(datas!=null){
            this.datas = datas;
        }
    }

    @Override
    public int getCount() {
        if(datas!=null && datas.size()>0){
            return datas.size();
        }else {
            return 0;
        }
    }

    @Override
    public Tip getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.item_layout, null);
            viewHolder = new ViewHolder();
            viewHolder.poi_field_id = (TextView) convertView.findViewById(R.id.poi_field_id);
            viewHolder.poi_value_id = (TextView) convertView.findViewById(R.id.poi_value_id);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder)convertView.getTag();
        }
        Tip tip = datas.get(position);
        viewHolder.poi_field_id.setText(tip.getName());
        viewHolder.poi_value_id.setText(tip.getDistrict());
        return convertView;
    }

    public class ViewHolder{

        public TextView poi_field_id;
        public TextView poi_value_id;

    }
}
